package com.gxa.admin.controller;

import com.gxa.admin.entity.vo.GoodsAuditVo;
import com.gxa.admin.param.GoodsParam;
import com.gxa.admin.param.UserParam;
import com.gxa.admin.service.GoodsService;
import com.gxa.o2o.core.dto.ResultDTO;
import com.gxa.o2o.core.pojo.Category;
import com.gxa.o2o.core.pojo.Goods;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/goods")
@Api(tags = "后台----商品管理")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @ApiOperation(value = "查询所有（未被删除的、以及已审核）")
    @PostMapping("/listAll")
    public ResultDTO listAll(){
        return goodsService.listAll();
    }

    @PostMapping("/listByParam")
    @ApiOperation(value = "通过条件分页查询（包括已被删除的）")
    public ResultDTO listByParam(@RequestBody GoodsParam param){
        return goodsService.listByParam(param);
    }

    @PostMapping("/addOne")
    @ApiOperation(value = "添加")
    public ResultDTO addOne(Goods goods){
        return goodsService.add(goods);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除（包括批量删除）,传入数组(ids)，json传参")
    public ResultDTO delete(@RequestBody List<String> ids){
        return goodsService.delete(ids);
    }

    @PostMapping("/findById")
    @ApiOperation(value = "通过id查询商品")
    public ResultDTO findById(@RequestParam("id") String id){
        return goodsService.findById(id);
    }



    @PostMapping("/audit")
    @ApiOperation(value = "商品审核")
    public ResultDTO audit(GoodsAuditVo goodsAuditVo){
        return goodsService.audit(goodsAuditVo);
    }


    @PostMapping("/offShelf")
    @ApiOperation(value = "违规下架（包括批量违规下架）,传入数组(ids)，json传参")
    public ResultDTO offShelf(@RequestBody List<String> ids){
        return goodsService.offShelf(ids);
    }

    @PostMapping("/updateOne")
    @ApiOperation(value = "修改（id必传）")
    public ResultDTO updateOne(Goods goods){
        return goodsService.updateOne(goods);
    }
}
